<!--勘察规范新增/编辑-->
<template>
  <div class="app-container-add">
    <el-dialog
      v-dialogDrag
      :title="dialogTitle"
      :visible.sync="dialogVisible"
      class="dialogStyleSmall"
      :before-close="cancel"
    >
      <el-form
        v-if="dialogVisible"
        ref="addForm"
        class="dialog-form"
        :model="formData"
        label-width="auto"
      >
        <el-row :gutter="20">
          <el-col :span="24">
            <el-form-item label="规范名称" prop="standardName">
              <span class="detail-info">{{ formData.standardName }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="规范编号" prop="standardCode">
              <span class="detail-info">{{ formData.standardCode }}</span>
            </el-form-item>
          </el-col>
          <el-col :span="24">
            <el-form-item label="附件" prop="attachId">
              <template slot="label">
                <span class="labelTitle" v-html="`附&emsp;&emsp;件`" />
              </template>
              <FileUplodeOne
                ref="fileUplode"
                :read-only="readOnly"
                :edit-file-list="FileList"
                @getFileIdsList="getFileList"
              />
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-dialog>
  </div>
</template>

<script>
// 页面接口
import { getStandardById } from '@/api/system/standard/index'
// 附件上传
import FileUplodeOne from '@/components/Upload/FileUplodeOne'
export default {
  name: 'Add',
  components: {
    FileUplodeOne
  },
  data() {
    return {
      /* 新增 start*/
      dialogTitle: '', // 弹层标题
      dialogVisible: false, // 弹层是否显示
      btnDisabled: false, // 确定按钮
      formData: { // 新增数据
        standardName: '', // 规范名称
        standardCode: '', // 规范编号
        attachId: ''// 附件
      },
      readOnly: true,
      FileList: []// 附件
    }
  },
  computed: {
  },
  mounted() {
  },
  methods: {
    /* 详情弹层 start*/
    // 从父组件获取参数的方法
    handleAdd(title, id) {
      this.dialogVisible = true
      this.dialogTitle = title
      if (id) {
        this.getDetailById(id)
      }
    },
    // 获取详情
    getDetailById(id) {
      getStandardById(id).then(res => {
        if (res) {
          this.formData = { ...res.data }
          if (res.data.attachIdList && res.data.attachIdList.length > 0) {
            this.FileList = res.data.attachIdList
          }
        }
      })
    },
    // 关闭
    cancel() {
      this.dialogVisible = false
    },
    /* 详情弹层 end*/
    /** ************ 文件上传start *******************/
    // 接受文件上传 组件 回传过来的文件id
    getFileList(fileIdsList, deleteFileIds) {
      this.formData.attachId = fileIdsList[0].fileId
      this.formData.attachIdDelete = deleteFileIds
    }
    /** ************ 文件上传end *******************/
  }
}
</script>

